package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.entity.News;
import com.woniu.mapper.AdminMapper;
import com.woniu.mapper.NewsMapper;
import com.woniu.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News>  implements INewsService {

    @Autowired
    AdminMapper adminMapper;
    @Override
    public News getNewsDetail(Integer id){
        News news = this.getById(id);
        news.setAdmin(adminMapper.selectById(news.getAid()));
        return  news;
    }

//    @Override
//    public Page<News> getNewsList(Integer pageNum, Integer pageSize, String name) {
//        Page<News> page = new Page<>(pageNum, pageSize);
//        LambdaQueryWrapper<News> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.like(News::getName, name);
//        return this.page(page, queryWrapper);
//    }

    @Override
    public Page<News> getNewsList(int pageIndex, int pageSize){
          Page pageObj = new Page<>(pageIndex, pageSize);
          LambdaQueryWrapper<News> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(News::getName, "");

         return this.page(pageObj, lambdaQueryWrapper);
    }
}
